package cc.rengu.igas.channel.cups.core.realize.impl;

import cc.rengu.igas.channel.cups.common.constant.CupsConfigConstant;
import cc.rengu.igas.channel.cups.core.realize.CupsInstCodeService;
import cc.rengu.igas.share.core.model.MchntInfo;
import cc.rengu.igas.share.core.realize.MchntService;
import cc.rengu.igas.share.core.realize.impl.MchntServiceImpl;
import cc.rengu.oltp.utility.util.StringUtil;
import cc.rengu.oltp.utility.util.XmlConfigUtil;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;


/**
 * mac服务实现
 *
 * @author Gendb
 */
public class CupsInstCodeServiceImpl implements CupsInstCodeService {
    private RgLogger rglog = RgLog.getLogger(this.getClass().getName());


    @Override
    public String genCupsAcqInstCode(String instId, String mchntNo) throws Exception {
        String acqInstCode = XmlConfigUtil.getXmlConfigCacheKeyValue(CupsConfigConstant.CUPS_CONF_NODE, CupsConfigConstant.CUPS_ACQ_INS_CODE);
        MchntService mchntService = new MchntServiceImpl();
        MchntInfo mchntInfo = mchntService.getMchntInfo(instId, mchntNo);
        if (null == mchntInfo || StringUtil.isEmptyOrNull(mchntInfo.getCupsInstId())) {
            /*未获取到银联子商户*/
            rglog.error("获取银联收单机构号失败", instId);
        } else {
            if (!StringUtil.isEmptyOrNull(mchntInfo.getCupsAreaCode())) {
                acqInstCode = acqInstCode.substring(0, 4) + mchntInfo.getCupsAreaCode();
            }
        }
        return acqInstCode;
    }
}
